package com.davidfauthoux.client;

import com.google.gwt.user.client.ui.HTML;

public final class Utils {

	public static native boolean isInternetExplorer() /*-{
		if (!navigator.userAgent)
			return false;
	 	if (navigator.userAgent.indexOf("MSIE") >= 0)
	 		return true;
	 	return false;
	}-*/;

	public static HTML createSwf(String path, String objectId, int width, int height) {
		if (Utils.isInternetExplorer()) {
			String url = path; //%% + "?_date=" + System.currentTimeMillis(); // do not cache SWF (or ExternalInterface.addCallback will not work on reload)
			return new HTML(
				"<object " +
						"classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
						"codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" " +
						"width=\"" + width + "\" " +
						"height=\"" + height + "\" " +
						"id=\"" + objectId + "\" " +
						"name=\"" + objectId + "\" " +
						"align=\"middle\" " +
						"data=\"" + url + "\" " + // required to make ExternalInterface.addCallback working
						"type=\"application/x-shockwave-flash\"" +
						">"
				+ 	"<param name=\"bgcolor\" value=\"#000\"></param>"
                + 	"<param name=\"movie\" value=\"" + url + "\"></param>"
                + 	"<param name=\"quality\" value=\"best\"></param>"
                + 	"<param name=\"allowscriptaccess\" value=\"always\"></param>"
                + 	"<param name=\"loop\" value=\"false\"></param>"
                + 	"<param name=\"menu\" value=\"false\"></param>"
                + 	"<param name=\"allowfullscreen\" value=\"true\"></param>"
                + "</object>"
                );
		} else {
			return new HTML(
					"<embed " +
						"bgcolor=\"#000\" " +
						"loop=\"false\" " +
						"menu=\"false\" " +
						"quality=\"best\" " +
						"width=\"" + width + "\" " +
						"height=\"" + height + "\" " +
						"id=\"" + objectId + "\" " +
						"align=\"middle\" " +
						"allowscriptaccess=\"always\" " +
						"allowfullscreen=\"true\" " +
						"type=\"application/x-shockwave-flash\" " +
						"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" " +
						"src=\"" + path + "\"" +
						">" +
					"</embed>");
		}
	
	}
}
